package com.spark.mock.controller;

import com.alibaba.fastjson.JSON;
import com.spark.mock.service.SparkService;
import com.spark.mock.util.HttpUtil;
import com.spark.mock.utils.PropertiesUtil;
import com.spark.mock.vo.UserVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;


/**
 * @author ：wangshuliang
 * @date ：Created in 2021/9/19 17:44
 * @description：创建测试类
 * @modified By：
 * @version: $
 */
@RestController
@Slf4j
public class TestController {

    @Autowired
    private SparkService sparkService;

    @PostMapping("/api/getName")
    public String getName(@RequestParam("name") String name){
        return name+"测试返回";
    }

    @PostMapping("/api/getBody")
    public UserVo getBody(@RequestBody UserVo userVo){
        return userVo;
    }

    @PostMapping("/api/mockBean")
    public String getMock(){
        return sparkService.getName("wsl");
    }

    @PostMapping("/api/getMockMulParamters")
    public String getMockMulParamters(){
        return sparkService.getName("Spark","24");
    }


    @PostMapping("/api/getToken")
    public String getSAPPQRCode() {
        String token ="";
        String url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+ token;
        String res = "";
        HttpUtil httpUtil = new HttpUtil();
        try {
            Map<String, String> data = new HashMap<>();
            data.put("scene","123"); // 此处数据无法修改
            log.info("请求微信小程序获取访问二位码url{}", url);
            res = httpUtil.postUTF8(url, JSON.toJSONString(data));
            log.info("请求微信小程序获取访问二位码url{}", res);
            // 将返回的字符串json化
        }catch (Exception ex){
            log.error("请求微信小程序获取访问二位码异常{}",ex.toString());
        }
        return null;
    }

    @GetMapping("/api/properties")
    public String getProperties(){
        return PropertiesUtil.getValue("Spark","SEVEN");
    }
}
